package com.kkkk.rest.common.dto;

import lombok.Data;

@Data
public class ResponseMessage<T> {

    protected String code;
    protected String msg;
    protected T data;


    /**
     * 异常相关字段(Json)
     */
    protected String fields;


    /**
     * 错误产生 系统来源
     */
    protected String service;


    public static ResponseMessage success() {
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setCode("200");
        return responseMessage;
    }

    public static ResponseMessage success(Object data) {
        ResponseMessage responseMessage = success();
        responseMessage.setData(data);
        return responseMessage;
    }

    public static ResponseMessage error(String code, String msg) {
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setCode(code);
        responseMessage.setMsg(msg);
        return responseMessage;
    }

    public boolean isSuccess() {
        return this.code.equals("200");
    }
}
